package com.xzq.wanandroid.Utils;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName : ActivityManager
 * @Description : activity的管理类
 * @Author : xzq
 * @Date: 2021-04-30 17:04
 * @Version :
 */
public class ActivityManager {

    private List<Activity> activityList = new ArrayList<>();
    //newInstance
    private static final ActivityManager mInstance=new ActivityManager();

    public static ActivityManager getmInstance() {
        return mInstance;
    }

    //添加activity
    public void addActivity(Activity activity){
        if (activity!=null){
            activityList.add(activity);
        }
    }

    //删除activity
    public void removeActivity(Activity activity){
        if (activity!=null){
            activityList.remove(activity);
        }

    }


    //调用方法，结束退出APP，清除所有的activity实例
    public void finishApp(){
        if (activityList!=null&&!activityList.isEmpty()){
            for (Activity activity: activityList) {
                activity.finish();
            }
            activityList.clear();
        }
    }
}


